<?php


namespace app\api\model;

use think\Model;

/**
 * 用户详细信息
 * Class UserInfoModel
 * @package app\api\model
 */
class UserInfoModel extends Model
{

    /**
     * 设置表名
     * @var string
     */
    protected $table = 'te_userinfo';

    /**
     *
     * 添加表单信息
     */
    public static function userInfoAdd($params){

        $userInfo = [

              'user_id' => $params['user_id'],
              'name' => $params['name'],
              'sex' => $params['sex'],
              'phone' => $params['phone'],
              'email' => $params['email'],
              'wechat_num' => $params['wechat_num'],
              'is_live_experience' => $params['is_live_experience'],
              'platform_name' => isset($params['platform_name']) ? $params['platform_name'] : '',
              'nickname' => isset($params['nickname']) ? $params['nickname'] : '',
              'room_num' => isset($params['room_num']) ? $params['room_num'] : '',
              'live_intention' => $params['live_intention'],
              'is_full_time' => $params['is_full_time'],
              'is_base_device' => $params['is_base_device'],
              'partition' => $params['partition'],
              'other_partition' => isset($params['other_partition']) ? $params['other_partition'] : '',
              'partition_content' => isset($params['partition_content']) ? $params['partition_content'] : '',
              'other_partition_content' => isset($params['other_partition_content']) ? $params['other_partition_content'] : '',
              'expose_plan' => $params['expose_plan'],
              'week_days' => $params['week_days'],
              'other_week_days' => isset($params['other_week_days']) ? $params['other_week_days'] : '',
              'days_time_slot' => $params['days_time_slot'],
//              'is_media_num' => $params['is_media_num'],
              'img1' => isset($params['img1']) ? $params['img1'] : '',
//              'is_okmai' => $params['is_okmai'],
              'imgs2' => isset($params['imgs2']) ? $params['imgs2'] : '',
              'self_info' => $params['self_info'],
        ];
        if (self::where(['user_id'=>$params['user_id']])->find()){

            $userInfo['update_at'] = time();
            return self::where(['user_id'=>$params['user_id']])->update($userInfo);
        }else{

            return self::insert($userInfo);
        }

    }

    /**
     *
     * 表单详细信息
     */
    public static function userInfo($id){

        return self::where(['user_id'=>$id])->field('id,is_live_experience,is_media,anchor_type,is_full_time
        ,nickname,sex,phone,wechat_num,live_platform,game_id,grade_id,hot_value,info')->find();
    }
}